package com.demo2do.fms.admin.dao.supplier;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.driver.DriverEvent;
import com.demo2do.fms.entity.supplier.common.Supplier;

/**
 *
 * @author Ark
 *
 */
@Dao("hibernate")
public interface DriverEventDao {

    /**
     * @return
     */
    @Query("SELECT COUNT(*) FROM DriverEvent WHERE disabled = false")
    public int count();
    
    /**
     * @param supplier
     * @return
     */
    @Query("SELECT COUNT(*) FROM DriverEvent WHERE disabled = false AND supplier = :supplier")
    public int count(@Variable("supplier") Supplier supplier);
    
    /**
     * @param supplierIds
     * @return
     */
    @Query("SELECT COUNT(*) FROM DriverEvent WHERE disabled = false AND supplier.id IN (:supplierIds)")
    public int count(@Variable("supplierIds") List<Long> supplierIds);
    
    /**
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM DriverEvent WHERE disabled = false ORDER BY createTime DESC")
    public List<DriverEvent> list(@Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param supplier
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM DriverEvent WHERE disabled = false AND supplier = :supplier ORDER BY createTime DESC")
    public List<DriverEvent> list(@Variable("supplier") Supplier supplier, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param supplierIds
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM DriverEvent WHERE disabled = false AND supplier.id IN (:supplierIds) ORDER BY createTime DESC")
    public List<DriverEvent> list(@Variable("supplierIds") List<Long> supplierIds, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
}
